package problem.nc038;

import java.util.*;

public class Solution {
    public ArrayList<Integer> spiralOrder(int[][] matrix) {
        ArrayList<Integer> ret = new ArrayList<>();
        int[] matrix1 = matrix[0];
        // i 控制行
        // j 控制列
        for (int i = 0; i < matrix.length; i++) {
            if ((i + 1) % 2 == 1) {
                for (int j = 0; j < matrix[i].length; j++) {
                    ret.add(matrix[i][j]);
                }
            } else {
                for (int j = matrix.length - 1; j >= 0; j--) {
                    ret.add(matrix[i][j]);
                }
            }
        }
        return ret;
    }

    public static void main(String[] args) {
        int[][] arr ={
                {1,2,3},
                {4,5,6},
                {7,8,9}
        };
        Solution s = new Solution();
        System.out.println(s.spiralOrder(arr));
    }
}
